/*****************************************
 *   Library is under MIT License (MIT)
 *   Copyright (c) 2012 Andreas Herz
 ****************************************/
/**
 * @class draw2d.shape.widget.Slider
 * See the example:
 *
 *     @example preview small frame
 *     
 *     var slider = new draw2d.shape.widget.Slider({width:120, height:20});
 *     canvas.add( slider,100,60);
 * 
 * @extends draw2d.shape.widget.Widget
 */
Rainier.UI.V2.SwitchFigure = Rainier.UI.V2.DeviceBoxFigure.extend({
    
    NAME : "Rainier.UI.V2.SwitchFigure",
    
    DEFAULT_COLOR_THUMB : new draw2d.util.Color("#bddf69"),
    DEFAULT_COLOR_BG    : new draw2d.util.Color("#d3d3d3"),
    
    
    init: function(attr, setter, getter ){

        this._super(attr);
        this.currentState = true;
    },
    
    /**
     * 函数名称：Rainier.UI.V2.DeviceBoxFigure.createSet<br>
     * 函数功能：创建背景图片<br>
     * 参数输入：无<br>
     * 参数输出：无<br>
     * 函数返回：set:canvas.paper.set<br>
     * 异常信息：无<br>
     */
    createSet: function() {
        var set = this._super();
        this.onDynamicChange(this.currentState);
        return set;
    },

    setCurrentState : function(switchState){
        this.currentState = switchState;
        this.onDynamicChange(this.currentState);
    },

    updateDynamicSet : function(){
        this.onDynamicChange(this.currentState);
    },

    onDynamicChange : function(switchState){
        var _this = this;

        var imageOff = this.subImageList.get(0);
        var imageOn = this.subImageList.get(1);
        if (imageOn) {
            if (switchState) {
                imageOn.image.show();
            }
            else{
                imageOn.image.hide();
            }
        }
        if (imageOff) {
            if (switchState) {
                imageOff.image.hide();
            }
            else{
                imageOff.image.show();
            }
        }
    },
});